<template>
  <div class="info-container">
    <el-card style="height: 100%">
      <search-tool @onSearch="handleSearch"></search-tool>
      <div class="addmore">
        <el-button type="primary" @click="addMore" style="margin-bottom: 24px"
          >添加</el-button
        >
      </div>
      <el-table
        :data="tableData"
        style="width: 100%"
        v-loading="loading"
        height="75%"
        align-items="center"
      >
        <el-table-column label="序号" type="index" />
        <el-table-column prop="teamName" label="队伍名称" width="150" />
        <el-table-column prop="teamType" label="队伍类型" widthw="150" />
        <el-table-column prop="teamMechanism" label="队伍机制" />
        <el-table-column prop="teamAddress" label="队伍地址" width="260" />
        <el-table-column prop="captainName" label="队长姓名" />
        <el-table-column prop="contactNumber" label="联系电话" width="150" />
        <el-table-column prop="teamSize" label="队伍人数" />
        <el-table-column prop="mainEquipment" label="主要装备" width="200" />
        <el-table-column fixed="right" label="操作" width="120">
          <template #default="scope">
            <div class="action-row">
              <!-- <el-icon
                @click.prevent="editRow(scope.$index, scope.row)"
                color="#17b6f9"
                size="18"
                ><EditPen
              /></el-icon> -->
              <svg-icon
                icon="edit"
                @click.prevent="editRow(scope.$index, scope.row)"
              />
              <div class="has-more"></div>
              <!-- <el-icon
                @click="deleRow(scope.$index, scope.row)"
                color="#e8574a"
                size="18"
                ><Delete
              /></el-icon> -->
              <svg-icon
                icon="dele"
                @click.prevent="deleRow(scope.$index, scope.row)"
              />
            </div>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination"
        :currentPage="page"
        :page-sizes="[5, 10, 20]"
        :page-size="size"
        layout="prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <add-dialog
      :title="dialogTitle"
      :rowData="curRowData"
      :visible="visibleDialog"
      @onReload="reloadPage"
      @onCloes="onCloes"
    ></add-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SearchTool from './components/SearchTool/index.vue'
import AddDialog from './components/AddDialog/index'
import { allList, ListSearch, ListDelet } from '@/api/dataMeng'
import { ElMessageBox } from 'element-plus'
import { message } from '@/utils/message'
import { Delete, EditPen } from '@element-plus/icons-vue'

const params = ref({})
const tableData = ref([])
const loading = ref(false)
const page = ref(1)
const total = ref(0)
const size = ref(8)
const dialogTitle = ref('新建工单')
const visibleDialog = ref(false)
const curRowData = ref({})
const ruleForm = ref(null)

// 查询所有数据
const getListData = async (params) => {
  loading.value = true
  const res = await allList(params, page.value, size.value)
  loading.value = false
  tableData.value = res.rows
  total.value = res.total
}
getListData(params.value)
//查询条件相关
const handleSearch = async (paramsData) => {
  loading.value = true
  const res = await ListSearch({
    mainEquipment: paramsData.mainEquipment,
    teamName: paramsData.teamName
  })
  loading.value = false
  tableData.value = res
}
const addMore = () => {
  dialogTitle.value = '新建救援队'
  curRowData.value = {}
  visibleDialog.value = true
}
const teamDele = (row, indexa) => {}
const reloadPage = () => {
  curRowData.value = {}
  getListData(params.value)
  visibleDialog.value = false
}
// 编辑信息
const editRow = (index, scoe) => {
  dialogTitle.value = '编辑救援队'
  curRowData.value = scoe
  visibleDialog.value = true
}
// 删除信息
const deleRow = (index, scop) => {
  ElMessageBox.confirm('确定删除此救援队吗?', '删除救援队', {
    confirmButtonText: '确定',
    cancelButtonText: '取消'
  })
    .then(() => {
      // 删除
      deleList(scop.id)
    })
    .catch(() => {
      // catch error
    })
}
const deleList = async (id) => {
  const res = await ListDelet(id)
  message({ type: 'success', message: '删除成功!' })
  getListData(params.value)
}
const onCloes = () => {
  curRowData.value = {}
  visibleDialog.value = false
}
const handleSizeChange = (val) => {
  size.value = val
  getListData(params.value)
}
const handleCurrentChange = (val) => {
  page.value = val
  getListData(params.value)
}
</script>

<style lang="scss" scoped>
.info-container {
  width: 100%;
  height: 100%;
  .pagination {
    width: 100%;
    height: 32px;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: end;
  }
  .action-row {
    display: flex;
    .action-btn {
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      line-height: 19px;
      color: #547bf1;
      cursor: pointer;
    }
    .has-more {
      width: 2px;
      height: 10px;
      margin-right: 10px;
      margin-left: 10px;
      margin-top: 5px;
    }
  }
}
</style>
